package com.aponisipsis.gl3d.geometry;

import java.nio.FloatBuffer;

import org.lwjgl.BufferUtils;
import org.lwjgl.util.vector.Matrix4f;
import org.lwjgl.util.vector.Vector3f;

public class Transform {
	private Matrix4f matrix;
	private FloatBuffer buffer;
	boolean changed;
	
	public Transform(Matrix4f mtx){
		this.matrix = mtx;
		buffer = BufferUtils.createFloatBuffer(16);
		changed = true;
	}
	
	public Transform(){
		this(new Matrix4f());
	}
	
	public void rotate(float angle, float x, float y, float z){
		matrix.rotate(angle, new Vector3f(x,y,z));
		changed = true;
	}
	
	public void translate(float x, float y, float z){
		matrix.translate(new Vector3f(x,y,z));
		changed = true;
	}
	
	public void scale(float x, float y, float z){
		matrix.scale(new Vector3f(x,y,z));
		changed = true;
	}
	
	public FloatBuffer getStoredMatrix(){
		if(changed){
			matrix.store(buffer);
			buffer.flip();
		}
		
		return buffer;
	}
}
